#include "common/time/time.h"

String getHMTime(unsigned long rawTime)
{
    unsigned long hours = (rawTime % 86400L) / 3600;
    String hoursStr = hours < 10 ? "0" + String(hours) : String(hours);

    unsigned long minutes = (rawTime % 3600) / 60;
    String minuteStr = minutes < 10 ? "0" + String(minutes) : String(minutes);

    return hoursStr + ":" + minuteStr;
}

String getMSTime(unsigned long rawTime)
{
    unsigned long minutes = (rawTime % 3600) / 60;
    String minuteStr = minutes < 10 ? "0" + String(minutes) : String(minutes);

    unsigned long seconds = rawTime % 60;
    String secondStr = seconds < 10 ? "0" + String(seconds) : String(seconds);

    return minuteStr + ":" + secondStr;
}

String getFormattedTime(unsigned long rawTime)
{
    unsigned long hours = (rawTime % 86400L) / 3600;
    String hoursStr = hours < 10 ? "0" + String(hours) : String(hours);

    unsigned long minutes = (rawTime % 3600) / 60;
    String minuteStr = minutes < 10 ? "0" + String(minutes) : String(minutes);

    unsigned long seconds = rawTime % 60;
    String secondStr = seconds < 10 ? "0" + String(seconds) : String(seconds);

    return hoursStr + ":" + minuteStr + ":" + secondStr;
}
String getFormattedTime(int16_t year, int8_t month, int8_t mday,int8_t hour, int8_t min, int8_t sec)
{
    String monthStr = month < 10 ? "0" + String(month) : String(month);
    String mdayStr = mday < 10 ? "0" + String(mday) : String(mday);
    String hourStr = hour < 10 ? "0" + String(hour) : String(hour);
    String minStr = min < 10 ? "0" + String(min) : String(min);
    String secStr = sec < 10 ? "0" + String(sec) : String(sec);
    return String(year) + "-" + monthStr  + "-" +  mdayStr  + " " + hourStr + ":" + minStr + ":" + secStr;
}